package com.hippo.core.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import com.hippo.core.ui.theme.HippoTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TitleBar(
    modifier: Modifier = Modifier,
    title: String? = null,
    onBack: (() -> Unit),
    rightImageVector: ImageVector? = null,
    onRightClick: ((() -> Unit))? = null,
) {

    TopAppBar(
        colors = TopAppBarDefaults.topAppBarColors(
            containerColor = Color.White,
        ),
        modifier = modifier,
        navigationIcon = {
            IconButton(onClick = onBack) {
                Icon(Icons.AutoMirrored.Filled.ArrowBack, null)
            }
        },
        title = {
            Text(
                text = title ?: "",
                textAlign = TextAlign.Center,
                fontSize = 18.sp,
                modifier = modifier.fillMaxWidth(),
                color = Color.Black,
                style = TextStyle(
                    fontWeight = FontWeight.Bold
                )
            )
        },
        actions = {
            if (onRightClick != null && rightImageVector != null) {
                IconButton(onClick = onRightClick) {
                    Icon(imageVector = rightImageVector, null)
                }
            }else{
                IconButton(onClick = {}) {
                }
            }
        }
    )

}


@Preview
@Composable
private fun TitleBarPreview() {
    HippoTheme {
        TitleBar(
            title = "Title",
            onBack = {},
            rightImageVector = Icons.Default.Settings,
            onRightClick = {}
        )
    }
}
